package org.example.test5.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.example.test5.model.User;

@Mapper
public interface UserMapper {
    // 根据用户名查询用户
    @Select("select * from user where uname = #{uname}")
    User findUserByName(String uname);

    // 根据id查询用户
    @Select("select * from user where id = #{id}")
    User findUserById(int id);

    // 添加用户
    @Insert("insert into user(uname,upwd) values(#{uname},#{upwd})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertUser(User user);

    // 修改密码
    @Select("update user set upwd = #{newPassword} where id = #{id}")
    void updatePassword(int id, String newPassword);

}